<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="主题消息字段" @ok="handleSubmit" width="700px" destroyOnClose>
    <BasicTable @register="registerTable" >
    </BasicTable>
  </BasicModal>
</template>
<script lang="ts" name="EvbMsgFieldLib" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from "/@/components/Modal"
import { BasicTable, useTable } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { fieldLibColumns } from '../data';
import * as evbApi from '/@/api/infra/eventBus';
import { useMessage } from '/@/hooks/web/useMessage';

const { t } = useI18n('');
const { createMessage } = useMessage();
const emit = defineEmits(["register", "success"])
const record = ref()

const [registerTable, { reload, getSelectRowKeys, expandAll }] = useTable({
  api: evbApi.listTopicMsgField,
  columns: fieldLibColumns,
  bordered: false,
  beforeFetch: (params) => {
    params.topicCode = record.value.topicCode;
    return params;
  },
  showIndexColumn: false,
  immediate: false,
  showTableSetting: false,
  useSearchForm: false,
  defaultExpandAllRows: true,
  isTreeTable: true,
  clickToRowSelect: false,
  pagination: false,
  canResize: false,
  rowKey: 'id',
  rowSelection: {
    type: "checkbox",
    columnWidth: 20,
    onChange: (selectedRowKeys: (string | number)[]) => {

    },
  }
})


const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  setModalProps({ confirmLoading: false })
  console.log('record', data.record)
  record.value = data.record
  await reload()
  expandAll()
})

const handleSubmit = () => {
  closeModal()
  const keys = getSelectRowKeys()
  if (keys.length == 0) {
    return
  }
  emit('success', keys)
}
</script>
